package com.timber.util;
import java.io.Serializable;
import java.util.Vector;

/**
 * Store procedure Paramaters
 * @author rogephi
 *
 */
public class SLProcDescriptor implements Serializable {
	
	/**
	 * 
	 */
	private static final long serialVersionUID = -5629023862281042854L;

	/** stored proc name to get data */
	private String procName;
	
	/** vector of stored procedure parameters */
	private Vector procParams;

	/**
	 * Creates a proc params object
	 *
	 */
	public SLProcDescriptor() {
		clearProcP();
	}
	
	/**
	 * Creates a proc params object
	 *
	 */
	public SLProcDescriptor(String procName) {
		clearProcP();
		setProcName(procName);
	}
	/**
	 * clear stored proc parameters vector
	 */
	public void clearProcP() {
		procParams = new Vector();
	}

	/**
	 * add object to stored proc parameters vector pls use addProcParameter(
	 * Object o )
	 */
	public void addProcP(Object o) {
		procParams.add(o);
	}
	
	
	/**
	 * add paremeter object to procedure parameters vector
	 * 
	 * @param o
	 */
	public void addProcParameter(Object o) {
		procParams.add(o);
	}

	/**
	 * set procedure paramters vector to aV
	 */
	public void setProcParams(Vector aV) {
		procParams = aV;
	}
	
	public void setProcName(String s) {
		procName = s;
	}
	
	/**
	 * get stored proc name
	 * 
	 * @return
	 */
	public String getProcName() {
		return procName;
	};


	/**
	 * process vector of procParams and build comma seperated procedure
	 * parameters string
	 */
	public String getProcParams() {
		int i;

		StringBuffer buff = new StringBuffer(1000);

		for (i = 0; i < procParams.size(); i++) {
			Object o = procParams.elementAt(i);

			if (i > 0)
				buff.append(",");
			else
				buff.append(" ");

			if (o == null)
				buff.append("null");
			else if (o instanceof String)
				buff.append("'").append(((String) o).replace('\'', ' '))
						.append("'");
			else if (o instanceof Number)
				buff.append(o.toString());
			else if (o instanceof java.util.Date)
				buff.append("'").append(Global.dateOnly((java.util.Date) o))
						.append("'");
			else if (o instanceof Boolean) {
				if (o.equals(Boolean.FALSE))
					buff.append("0");
				else
					buff.append("1");
			}  else
				Util.error("[SLDataRecordsMgr getProcParams()]",
						"Unknown Proc Parameter Type   " + o);
		}

		return buff.toString();
	}

}
